package com.qianfeng.controller;

import com.qianfeng.dto.Page;
import com.qianfeng.dto.Result;
import com.qianfeng.entity.Employee;
import com.qianfeng.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@ResponseBody
@Controller
@CrossOrigin
@RequestMapping(value = "/employee")
public class EmployeeController {


    @Autowired
    private EmployeeService employeeService;

    @RequestMapping(value = "/addEmployee")
    public Result addEmployee(@RequestBody Employee employee){
        employeeService.addEmployee(employee);
        Result result = new Result();
        return result;
    }

    /**
     * 删除角色
     * @param empId
     * @return
     */
    @RequestMapping(value = "/deleteEmployee")
    public Result deleteEmployee(Integer empId){
        employeeService.deleteEmployee(empId);
        Result result = new Result();
        return result;
    }

    /**
     * 更新角色
     * @param employee
     * @return
     */
    @RequestMapping(value = "/updateEmployee")
    public Result updateEmployee(@RequestBody Employee employee){
        employeeService.updateEmployee(employee);
        Result result = new Result();
        return result;
    }

    @RequestMapping(value = "/getEmployeeList")
    public Result getEmployeeList(){
        List<Employee> employeeList = employeeService.getEmployeeList();
        Result result = new Result();
        result.setData(employeeList);
        return result;
    }


    @RequestMapping(value = "/getEmployeePage")
    public Result getEmployeePage(Integer pageNo,Integer pageSize){
        if(pageNo==null){
            pageNo=1;
        }
        if(pageSize==null){
            pageSize=5;
        }
        Page page = employeeService.getEmployeePage(pageNo,pageSize);
        Result result = new Result();
        result.setData(page);
        return result;

    }

    @RequestMapping(value = "/getListByEmpId")
    public Result getListByEmpId(Integer empId){
        List<Employee> list = employeeService.getListByEmpId(empId);
        Result result = new Result();
        result.setData(list);
        return result;
    }

}
